package com.mj.factory.processFlow;

import com.mj.factory.workOrder.WorkOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProcessFlowService {
    @Autowired
    ProcessFlowDao processFlowDao;

    Page<ProcessFlow> findAll(Pageable pageable) {
        return processFlowDao.findAll(pageable);
    }

    List<ProcessFlow> findAll() {
        return processFlowDao.findAll();
    }

    public List<ProcessFlow> findByWorkOrderId(long workOrder_id){
        return processFlowDao.findAllByWorkOrderId(workOrder_id);
    }

    public List<ProcessFlow> findByWorkOrderOrderBySequenceNumber(long workOrderId){
        WorkOrder wo = new WorkOrder();
        wo.setId(workOrderId);
        return processFlowDao.findByWorkOrderOrderBySequenceNumber(wo);
    }
    public List<ProcessFlow> findByWorkOrderIdAndSequenceNumber(long workOrderId,Integer sequenceNumber){
        return processFlowDao.findByWorkOrderIdAndSequenceNumber(workOrderId,sequenceNumber);
    }
    public List<ProcessFlow> findByWorkOrderIdOrderBySequenceNumber(long workOrderId){
        return processFlowDao.findByWorkOrderIdOrderBySequenceNumber(workOrderId);
    }


    public boolean delete(List<ProcessFlow> list){
        boolean flag=false;
        try {
            processFlowDao.deleteInBatch(list);
            flag=true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    public ProcessFlow findById(long id){
        return processFlowDao.findOne(id);
    }

    public void save(ProcessFlow technologicalProcess) {
        processFlowDao.save(technologicalProcess);
    }

}
